package controller;

import annotation.Controller;
import annotation.DependencyInjection;
import annotation.RequestMapping;
import annotation.Singleton;
import enums.RequestType;
import request.message.MessageListRequest;
import request.message.MessagePullRequest;
import request.message.MessageSendRequest;
import response.message.MessageListResponse;
import response.message.MessagePullResponse;
import response.message.MessageSendResponse;
import service.MessageService;

@Singleton
@Controller
public class MessageController {
    private MessageService messageService;

    @DependencyInjection
    public MessageController(MessageService messageService) {
        this.messageService = messageService;
    }

    @RequestMapping(RequestType.MessageList)
    public MessageListResponse getBothMessages(MessageListRequest request) {
        return messageService.getBothMessages(request.getSenderUsername(), request.getReceiverUsername());
    }

    @RequestMapping(RequestType.MessageSend)
    public MessageSendResponse sendMessage(MessageSendRequest request) {
        return messageService.sendMessage(request.getMessage());
    }

    @RequestMapping(RequestType.MessagePull)
    public MessagePullResponse pullLatestMessages(MessagePullRequest request) {
        return messageService.getLatestMessages(request.getSenderUsername(), request.getReceiverUsername());
    }
}
